*****************************************************************
*****************************************************************
** Bechtel, Michael M./Hainmueller, Jens/Margalit, Yotam
** "Policy Design and Domestic Support for International Bailouts."
** First posted: October 2012
** Published version: 2019, European Journal of Political Research 56 (4): 864–886.
*****************************************************************
*****************************************************************


clear
set more off
global dropboxpath = "/Users/mbechtel/Desktop/Repdata Bailouts EJPR"


use Repdata_EJPR.dta, clear

tsset contestid scenario
gen   lag_rate  = L1.rating
gen   r2minusr1 = rating - lag_rate
tab   r2minusr1 chosen

gen     consistent = 0 if r2minusr1!=.  & r2minusr1!=0
replace consistent = 1 if r2minusr1<0  & chosen==0 & r2minusr1 !=.
replace consistent = 1 if r2minusr1>0  & chosen==1 & r2minusr1 !=.
replace consistent = 1 if r2minusr1==0

egen cleanmarker = mean(consistent) , by(contestid)

recode rating (0/3=0) (4/6=1) , gen(acceptdd)
label define acc 0 "otherwise" 1 "vote in favour" 
label values acceptdd acc
label var acceptdd "vote in favour"

recode rating (0/2=0) (3=.) (4/6=1) , gen(acceptdd2)
label define acc2 0 "vote against" 1 "vote in favour" 
label values acceptdd2 acc2
label var acceptdd2 "vote in favour (no indifferent)"


recode rating (0/2=1) (3/6=0) , gen(rejectedd)
label define rec 0 "otherwise" 1 "vote against"
label values rejectedd rec
label var rejectedd "vote against"

recode rating (0/2=1) (3=.) (4/6=0) , gen(rejectedd2)
label define rec2 0 "vote in favour" 1 "vote against"
label values rejectedd2 rec2
label var rejectedd2 "vote against (no indifferent)"


recode rating (0=6) (6=0) (1=5) (5=1) (2=4) (4=2) , gen(ratingneg)
label var ratingneg "vote against (6-0)"



*****************************************************
* Figure 2: Share of Bailout Proposals Rejected by Respondent
*****************************************************

preserve
egen howmany = count(rejectedd) , by(ResponseID)
keep if howmany==8
collapse (mean) ratingneg rejectedd rejectedd2 acceptdd cleanmarker , by(ResponseID)
foreach x of varlist rejectedd rejectedd2 acceptdd {
replace `x' = 100*`x'
} 
tab  rejectedd if cleanmarker ==1
tab  acceptdd if cleanmarker ==1
tab  ratingneg if cleanmarker ==1
histogram rejectedd if cleanmarker ==1 , bin(9) percent fcolor(gs14) lcolor(none) ///
gap(8) ytitle(Percent of Sample) xtitle(Share of Bailout Packages Rejected by Respondents (in %)) scheme(s1color) 
graph export rejection_rates.pdf, replace
graph export rejection_rates.eps, replace
save fundamental.dta, replace
restore


*****************************************************
* Figure 3: The Effects of Bailout Policy Features on Voter Support
*****************************************************

sum acceptdd* rejectedd* if cleanmarker==1
sum acceptdd* rejectedd* 

cap drop label FeatTargetCountry2
recode FeatTargetCountry (1=4) (4=1) , gen(FeatTargetCountry2)
label define FeatTargetCountry2 1 "Spain" 2 "Ireland" 3 "Italy" 4 "Greece"
label values FeatTargetCountry2 FeatTargetCountry2
drop FeatTargetCountry
rename FeatTargetCountry2 FeatTargetCountry 

* rectected (for marginal effects plot)
reg rejectedd i.FeatTargetCountry i.FeatConditions i.FeatGershare i.FeatGercontrib i.FeatHaircut i.FeatEndors , cl(ResponseID) , if cleanmarker==1
outreg2 using resmain.xls, append adjr2
matrix outt = (e(b) \ vecdiag(e(V)))'
mat2txt , matrix(outt) saving(fig3) replace

*******************************
* Figure A.2: The Effect of Bailout Policy Features on Voter Support for Bailout (7 Point Scale)
*******************************

* rectected (7 point scale)
replace ratingneg = ratingneg + 1
reg ratingneg i.FeatTargetCountry i.FeatConditions i.FeatGershare i.FeatGercontrib i.FeatHaircut i.FeatEndors , cl(ResponseID) , if cleanmarker==1
outreg2 using resmain.xls, append adjr2
matrix outt = (e(b) \ vecdiag(e(V)))'
mat2txt , matrix(outt) saving(figA2) replace
mat2txt , matrix(outt) saving(oppose7scale) replace

*****************************************
* Figure A.3: The Effect of Bailout Policy Features on Voter Support for Bailout (Forced Choice)
*****************************************

* binary rating chosen
recode chosen (0=1) (1=0) , gen(chosen2)
reg chosen2 i.FeatTargetCountry i.FeatConditions i.FeatGershare i.FeatGercontrib i.FeatHaircut i.FeatEndors , cl(ResponseID) , if cleanmarker==1
outreg2 using resmain.xls, replace adjr2
matrix outt = (e(b) \ vecdiag(e(V)))'
mat2txt , matrix(outt) saving(figA3) replace


*****************************************************
* Figure 7: Voter Support for Various Bailout Packages
*****************************************************
 
reg rejectedd i.FeatTargetCountry i.FeatConditions i.FeatGershare i.FeatGercontrib i.FeatHaircut i.FeatEndors , cl(ResponseID) , if cleanmarker==1

capture drop fitted
predict fitted  if e(sample)
sum fitted, det

*** expected support for some policy proposals
* store matrix
mat store = J(1,9,.)

* 1th percentile
* List packages with support in order of 1st percentile
list fitted FeatTargetCountry FeatConditions FeatGershare FeatGercontrib FeatHaircut FeatEndors  if fitted >.3146715 & fitted<.32 , nolab
lincom _cons + 2.FeatTargetCountry + 2.FeatConditions + 19.FeatGershare + 123.FeatGercontrib + 20.FeatHaircut + 6.FeatEndors
* Adjust sequence below so that matches selection in line above and add percentile information
mat res = r(estimate) , r(se) , 2 , 2 , 19, 123, 20, 6, .01
mat store = store \ res

* 25th percentile
list fitted FeatTargetCountry FeatConditions FeatGershare FeatGercontrib FeatHaircut FeatEndors  if fitted >.4604092 & fitted<.47 , nolab
lincom _cons + 1.FeatTargetCountry + 4.FeatConditions + 21.FeatGershare + 123.FeatGercontrib + 20.FeatHaircut + 1.FeatEndors
mat res = r(estimate) , r(se) , 1,        4,        21,       123,        20,         1, .25
mat store = store \ res

lincom _cons + 4.FeatTargetCountry + 1.FeatConditions + 53.FeatGershare + 123.FeatGercontrib + 75.FeatHaircut + 1.FeatEndors
mat res = r(estimate) , r(se) , 4,         1,        53,       123,        75,         1, 999
mat store = store \ res     

* 75 percentile
list fitted FeatTargetCountry FeatConditions FeatGershare FeatGercontrib FeatHaircut FeatEndors   if fitted >.584365 & fitted<.584367 , nolab
lincom _cons + 3.FeatTargetCountry + 4.FeatConditions + 53.FeatGershare + 211.FeatGercontrib + 75.FeatHaircut + 3.FeatEndors
mat res = r(estimate) , r(se) ,  3,         4,        53,       211,        75,         3,  .75
mat store = store \ res 

* 99th percentile
list fitted FeatTargetCountry FeatConditions FeatGershare FeatGercontrib FeatHaircut FeatEndors   if fitted >.8127920 & fitted<.8127922 , nolab
lincom _cons + 1.FeatTargetCountry + 4.FeatConditions + 53.FeatGershare + 418.FeatGercontrib + 75.FeatHaircut + 2.FeatEndors
mat res = r(estimate) , r(se) , 1,         4,        53,       418,        75,         2 , 99
mat store = store \ res  

mat store = store[2...,1...]
matlist store
matrix colnames store = pe se FeatTargetCountry FeatConditions FeatGershare FeatGercontrib FeatHaircut FeatEndors percentile
matrix rownames store = 1 2 3 4 5
* Export matrix to txt
mat2txt , matrix(store) saving(policy2) replace



*************
* What a package of a given size (say, 211bn)
* would have to look like in order to secure 
* the support of 50% of German citizens.“

reg rejectedd i.FeatTargetCountry i.FeatConditions i.FeatGershare i.FeatGercontrib i.FeatHaircut i.FeatEndors , cl(ResponseID) , if cleanmarker==1

capture drop fitted
predict fitted  if e(sample)
sum fitted, det

*** expected support for some policy proposals
* store matrix
mat store = J(1,9,.)


* Packages with roughly 50% support
* Baseline package: 
set more off
list fitted FeatTargetCountry FeatConditions FeatGershare FeatGercontrib FeatHaircut FeatEndors   if fitted >.4950 & fitted<.4951, nolab
set more off
list fitted FeatTargetCountry FeatConditions FeatGershare FeatGercontrib FeatHaircut FeatEndors   if fitted >.5049 & fitted<.5050 , nolab


* actual policy  (Greece, 5 percent budget cuts, 50 % germany share, contribute 123 billion, 50 % haircut, government
/*
Receiver: Greece [Greece]
Germany's Contribution: EUR 67.8 bn [123bn] Germany's Share: 46%  [50%] (the Greek Eurozone bailout is EUR 144.6 bn now); total committment to ESM by Germany: EUR 168bn
Haircut: >95% [75%]
Conditions: 
- About 10% [10%] public spending cut (plans are to cut by about 20% until 2015)
- About 8% [5%] public layoffs (from 768,009 in 2010 to 712,157 in 2012)
Endorsements: The government endorsed the package. Experts seemed divided. [Government/ECB]
*/
* 1. Baseline package (actual package)
lincom _cons + 4.FeatTargetCountry + 1.FeatConditions + 27.FeatGershare + 123.FeatGercontrib + 75.FeatHaircut + 1.FeatEndors
mat res = r(estimate) , r(se) , 4,         1,        27,       123,        75,         1, 999
mat store = store \ res

* 4 With Germany'y share set at 19%
lincom _cons + 4.FeatTargetCountry + 1.FeatConditions + 19.FeatGershare + 123.FeatGercontrib + 75.FeatHaircut + 1.FeatEndors
mat res = r(estimate) , r(se) , 4,         1,        19,       123,        75,         1, .10
mat store = store \ res  

* 7 With haircut set at 20%
lincom _cons + 4.FeatTargetCountry + 1.FeatConditions + 27.FeatGershare + 123.FeatGercontrib + 20.FeatHaircut + 1.FeatEndors
mat res = r(estimate) , r(se) , 4,         1,        27,       123,        20,         1, 0.25
mat store = store \ res  

* 9 With spending cut 15%
lincom _cons + 4.FeatTargetCountry + 2.FeatConditions + 27.FeatGershare + 123.FeatGercontrib + 75.FeatHaircut + 1.FeatEndors
mat res = r(estimate) , r(se) , 4,         2,        27,       123,        75,         1, 0.35
mat store = store \ res

* 12 With endorser Council of Economic Advisors
lincom _cons + 4.FeatTargetCountry + 1.FeatConditions + 27.FeatGershare + 123.FeatGercontrib + 75.FeatHaircut + 5.FeatEndors
mat res = r(estimate) , r(se) , 4,         1,        27,       123,        75,         5, 0.50
mat store = store \ res

* 19 Italy (3) were the receiving country?
lincom _cons + 3.FeatTargetCountry + 1.FeatConditions + 27.FeatGershare + 123.FeatGercontrib + 75.FeatHaircut + 1.FeatEndors
mat res = r(estimate) , r(se) , 3,         1,        27,       123,        75,         1, 0.85
mat store = store \ res  

mat store = store[2...,1...]
matlist store
matrix colnames store = pe se FeatTargetCountry FeatConditions FeatGershare FeatGercontrib FeatHaircut FeatEndors percentile
matrix rownames store = 1 2 3 4 5 6 

* Export matrix to txt
mat2txt , matrix(store) saving(policy_supplevls) replace

tab FeatTargetCountry
tab FeatTargetCountry, nolab


*******************
* ********************************************************************
* Subgroups

* Figure 4: The Effects of Bailouts Policy Features on Voter Support, by Income Groups
* high income low income
egen hhincgr1 = cut(xxhhinc) , group(2) , if xxhhinc!=99
replace hhincgr1 = hhincgr1 + 1

forvalues i = 1/2 {
reg rejectedd i.FeatTargetCountry i.FeatConditions i.FeatGershare i.FeatGercontrib i.FeatHaircut i.FeatEndors , cl(ResponseID) ///
 , if cleanmarker==1 & hhincgr1==`i'
matrix outt = (e(b) \ vecdiag(e(V)))'
mat2txt , matrix(outt) saving(hhinc`i') replace
}

* Figure 5: The Effects of Bailout Policy Features on Voter Support by Ideology
* ideology
recode  xxrightideology (0/4=1) (5=.) (6/10=2), gen(rright)
forvalues i = 1/2 {
reg rejectedd i.FeatTargetCountry i.FeatConditions i.FeatGershare i.FeatGercontrib i.FeatHaircut i.FeatEndors , cl(ResponseID) ///
 , if cleanmarker==1 & rright==`i'
matrix outt = (e(b) \ vecdiag(e(V)))'
mat2txt , matrix(outt) saving(ideo`i') replace
}

* Figure 6: The Effects of Bailout Policy Features on Voter Support by Education
* education
capture drop eduu
recode xxeduc (1/2=1) (3/4=2), gen(eduu)
forvalues i = 1/2 {
reg rejectedd i.FeatTargetCountry i.FeatConditions i.FeatGershare i.FeatGercontrib i.FeatHaircut i.FeatEndors , cl(ResponseID) ///
 , if cleanmarker==1 & eduu==`i'
matrix outt = (e(b) \ vecdiag(e(V)))'
mat2txt , matrix(outt) saving(educ`i') replace
}

* Figure A1: The Effects of Bailout Policy Features on Voter Support by Stock Ownership
* ownstocks
capture drop eduu
recode xxownstocks (0=1) (1=2), gen(ownstocks)
forvalues i = 1/2 {
reg rejectedd i.FeatTargetCountry i.FeatConditions i.FeatGershare i.FeatGercontrib i.FeatHaircut i.FeatEndors , cl(ResponseID) ///
 , if cleanmarker==1 & ownstocks==`i'
matrix outt = (e(b) \ vecdiag(e(V)))'
mat2txt , matrix(outt) saving(ownstocks`i') replace
}

* Figure A.4: Effect of Bailout Policy Features on Voter Support for Bailout by Contest

forvalues i = 1/4 {
reg rejectedd i.FeatTargetCountry i.FeatConditions i.FeatGershare i.FeatGercontrib i.FeatHaircut i.FeatEndors , cl(ResponseID) ///
 , if cleanmarker==1 & conjointno==`i'
matrix outt = (e(b) \ vecdiag(e(V)))'
mat2txt , matrix(outt) saving(task`i') replace
}

*  Figure A.5: Effect of Bailout Policy Features on Voter Support for Bailout by Receiving Country
* by country
forvalues i = 1/4 {
reg rejectedd  i.FeatConditions i.FeatGershare i.FeatGercontrib i.FeatHaircut i.FeatEndors , cl(ResponseID) ///
 , if cleanmarker==1 & FeatTargetCountry==`i'
matrix outt = (e(b) \ vecdiag(e(V)))'
mat2txt , matrix(outt) saving(country`i') replace
}

clear
exit















